﻿using System.Collections.Generic;

namespace NUnit4PowerShell
{

    


    /// <summary>
    /// This class is a singleton providing the name of the file to execute
    /// It works like a unlimited queue (FIFO system)
    /// Once an item is Dequeued, the same item is enqueue at the queue end 
    /// </summary>
    public class FixtureProvider
    {
        #region Singleton region
        /// <summary>
        /// Private constructor for singleton
        /// </summary>
        private FixtureProvider()
        {
        }
        private static FixtureProvider instance;

        public static FixtureProvider Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FixtureProvider();
                }
                return instance;
            }
        }
        #endregion

        private Queue<string> _fixturesQueue = new Queue<string>();

        /// <summary>
        /// Provide the first item on the queue, remove it and reinject it at the end of the queue
        /// </summary>
        /// <returns></returns>
        private string Dequeue()
        {
            var item = _fixturesQueue.Dequeue();
            //_fixturesQueue.Enqueue(item);
            _lastEnqueued = item;
            return item;
        }

        private void Enqueue(string item)
        {
            _fixturesQueue.Enqueue(item);
        }

        private string _lastEnqueued;
        private string LastEnqueued()
        {
            return _lastEnqueued;
        }

        /// <summary>
        /// Contains the amount of item contained in the queue
        /// </summary>
        private int Count
        {
            get
            {
                return _fixturesQueue.Count;
            }
        }

        static public void AddOne(string item)
        {

            //Logger.Instance.Info("[FixtureProvider] AddOne " + item);
            FixtureProvider.Instance.Enqueue(item);
        }

        static public string GetOne()
        {

            
            if (FixtureProvider.Instance.Count == 0)
            {
                //Logger.Instance.Info("[FixtureProvider] GetOne NULL");
                return null;
            }
            var item = FixtureProvider.Instance.Dequeue();
            //Logger.Instance.Info("[FixtureProvider] GetOne " + item);
            return item;
        }
    }
}
